
import LanguageMng from "../../Managers/LanguageMng";
import LanguageMngTs from "../../Managers/LanguageMngTs";

cc.Class({
    extends: cc.Component,

    properties: {
        tagEnglish:{
            default:null,
            type:cc.Node
        },
        tagHindi:{
            default:null,
            type:cc.Node
        },
        tagTalugu:{
            default:null,
            type:cc.Node
        },
        tagTaimil:{
            default:null,
            type:cc.Node
        },
        tagGugilatter:{
            default:null,
            type:cc.Node
        },
        tagMalaty:{
            default:null,
            type:cc.Node
        },
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        let language = LanguageMng.language
        if(language === cc.gg.enumConfig.Languages.ENGLISH){
            this.tagEnglish.active = true
            this.tagHindi.active = false
            this.tagTalugu.active = false
            this.tagTaimil.active = false
            this.tagGugilatter.active = false
            this.tagMalaty.active = false
        }else if(language === cc.gg.enumConfig.Languages.HINDI){
            this.tagEnglish.active = false
            this.tagHindi.active = true
            this.tagTalugu.active = false
            this.tagTaimil.active = false
            this.tagGugilatter.active = false
            this.tagMalaty.active = false
        }else if(language === cc.gg.enumConfig.Languages.TALUGU){
            this.tagEnglish.active = false
            this.tagHindi.active = false
            this.tagTalugu.active = true
            this.tagTaimil.active = false
            this.tagGugilatter.active = false
            this.tagMalaty.active = false
        }else if(language === cc.gg.enumConfig.Languages.TAIMIL){
            this.tagEnglish.active = false
            this.tagHindi.active = false
            this.tagTalugu.active = false
            this.tagTaimil.active = true
            this.tagGugilatter.active = false
            this.tagMalaty.active = false
        }else if(language === cc.gg.enumConfig.Languages.GULILATTER){
            this.tagEnglish.active = false
            this.tagHindi.active = false
            this.tagTalugu.active = false
            this.tagTaimil.active = false
            this.tagGugilatter.active = true
            this.tagMalaty.active = false
        }else if(language === cc.gg.enumConfig.Languages.MALATY){
            this.tagEnglish.active = false
            this.tagHindi.active = false
            this.tagTalugu.active = false
            this.tagTaimil.active = false
            this.tagGugilatter.active = false
            this.tagMalaty.active = true
        }else {
            cc.warn("未知的语言类型：",language)
        }
    },

    start () {

    },

    // update (dt) {},

    onMenuLanguageClicked:function (event) {
        let btnName = event.target.name
        let language = cc.gg.enumConfig.Languages.ENGLISH
        if(btnName === "btn_english"){
            cc.gg.tdUtil.doSendTdEvent("click_menu_language_english","MenuLanguage")
            LanguageMng.language = cc.gg.enumConfig.Languages.ENGLISH
            cc.sys.localStorage.setItem('language',cc.gg.enumConfig.Languages.ENGLISH)
        }else if(btnName === "btn_hindi"){
            cc.gg.tdUtil.doSendTdEvent("click_menu_language_hindi","MenuLanguage")
            LanguageMng.language = cc.gg.enumConfig.Languages.HINDI
            cc.sys.localStorage.setItem('language',cc.gg.enumConfig.Languages.HINDI)
        }else if(btnName === "btn_taimil"){
            cc.gg.tdUtil.doSendTdEvent("click_menu_language_taimil","MenuLanguage")
            LanguageMng.language = cc.gg.enumConfig.Languages.TAIMIL
            cc.sys.localStorage.setItem('language',cc.gg.enumConfig.Languages.TAIMIL)
        }else if(btnName === "btn_talugu"){
            cc.gg.tdUtil.doSendTdEvent("click_menu_language_talugu","MenuLanguage")
            LanguageMng.language = cc.gg.enumConfig.Languages.TALUGU
            cc.sys.localStorage.setItem('language',cc.gg.enumConfig.Languages.TALUGU)
        }else if(btnName === "btn_gugilatter"){
            cc.gg.tdUtil.doSendTdEvent("click_menu_language_gugilatter","MenuLanguage")
            LanguageMng.language = cc.gg.enumConfig.Languages.GULILATTER
            cc.sys.localStorage.setItem('language',cc.gg.enumConfig.Languages.GULILATTER)
        }else if(btnName === "btn_malaty"){
            cc.gg.tdUtil.doSendTdEvent("click_menu_language_malaty","MenuLanguage")
            LanguageMng.language = cc.gg.enumConfig.Languages.MALATY
            cc.sys.localStorage.setItem('language',cc.gg.enumConfig.Languages.MALATY)
        }else {
            cc.error("选择语言的类型未知：",btnName)
            return
        }

        LanguageMng.loadLanguage(LanguageMng.language,function () {
            LanguageMngTs.loadLanguage(LanguageMng.language,function () {
                LanguageMngTs.loadLanguage(LanguageMng.language)
                cc.gg.gameDataUtil.goToLobby(true)
            })
        })
    }
});
